package com.cskaoyan.controller;

import com.cskaoyan.bean.BO.BasePageInfoBo;
import com.cskaoyan.bean.PO.*;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.AdminUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin")
public class AdminUserController {

    @Autowired
    AdminUserService adminUserService;

    @RequiresPermissions("admin:user:list")
    @RequestMapping("user/list")
    public BaseRespVo getUserList(BasePageInfoBo basePageInfoBo, String username, String mobile) {
        CommonData<MarketUser> commonData = adminUserService.getUserList(basePageInfoBo, username, mobile);
        return BaseRespVo.ok(commonData);
    }

    @RequiresPermissions("admin:user:detail")
    @RequestMapping("user/detail")
    public BaseRespVo getUserDetail(Integer id) {
        MarketUser marketUser = adminUserService.getUserDetail(id);
        return BaseRespVo.ok(marketUser);
    }

    @RequiresPermissions("admin:address:list")
    @RequestMapping("address/list")
    public BaseRespVo getAddressList(BasePageInfoBo basePageInfoBo, String name, Integer userId) {
        CommonData<MarketAddress> commonDataVo = adminUserService.getAddressList(basePageInfoBo, name, userId);
        return BaseRespVo.ok(commonDataVo);
    }

    @RequiresPermissions("admin:collect:list")
    @RequestMapping("collect/list")
    public BaseRespVo getCollectList(BasePageInfoBo basePageInfoBo, Integer userId, Integer valueId) {
        CommonData<MarketCollect> commonDataVo = adminUserService.getCollectList(basePageInfoBo, userId, valueId);
        return BaseRespVo.ok(commonDataVo);
    }

    @RequiresPermissions("admin:footprint:list")
    @RequestMapping("footprint/list")
    public BaseRespVo getFootprintList(BasePageInfoBo basePageInfoBo, Integer userId, Integer goodsId) {
        CommonData<MarketFootprint> commonDataVo = adminUserService.getFootprintList(basePageInfoBo, userId, goodsId);
        return BaseRespVo.ok(commonDataVo);
    }

    @RequiresPermissions("admin:history:list")
    @RequestMapping("history/list")
    public BaseRespVo getSearchHistoryList(BasePageInfoBo basePageInfoBo, Integer userId, String keyword) {
        CommonData<MarketSearchHistory> commonDataVo = adminUserService.getSearchHistoryList(basePageInfoBo, userId, keyword);
        return BaseRespVo.ok(commonDataVo);
    }

    @RequiresPermissions("admin:feedback:list")
    @RequestMapping("feedback/list")
    public BaseRespVo getFeedbackList(BasePageInfoBo basePageInfoBo, Integer id, String username) {
        CommonData<MarketFeedback> commonDataVo = adminUserService.getFeedbackList(basePageInfoBo, id, username);
        return BaseRespVo.ok(commonDataVo);
    }

    @RequiresPermissions("admin:user:update")
    @RequestMapping("user/update")
    public BaseRespVo updateUser(@RequestBody MarketUser marketUser) {
        int affectedRows = adminUserService.updateUser(marketUser);
        return BaseRespVo.ok(affectedRows);
    }


}
